package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysErrorConditions;
import com.ruoyi.system.service.ISysErrorConditionsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 故障条件Controller
 * 
 * @author ruoyi
 * @date 2022-05-11
 */
@RestController
@RequestMapping("/system/conditions")
public class SysErrorConditionsController extends BaseController
{
    @Autowired
    private ISysErrorConditionsService sysErrorConditionsService;

    /**
     * 查询故障条件列表
     */
    @PreAuthorize("@ss.hasPermi('system:conditions:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysErrorConditions sysErrorConditions)
    {
        startPage();
        List<SysErrorConditions> list = sysErrorConditionsService.selectSysErrorConditionsList(sysErrorConditions);
        return getDataTable(list);
    }

    /**
     * 导出故障条件列表
     */
    @PreAuthorize("@ss.hasPermi('system:conditions:export')")
    @Log(title = "故障条件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysErrorConditions sysErrorConditions)
    {
        List<SysErrorConditions> list = sysErrorConditionsService.selectSysErrorConditionsList(sysErrorConditions);
        ExcelUtil<SysErrorConditions> util = new ExcelUtil<SysErrorConditions>(SysErrorConditions.class);
        util.exportExcel(response, list, "故障条件数据");
    }

    /**
     * 获取故障条件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:conditions:query')")
    @GetMapping(value = "/{conId}")
    public AjaxResult getInfo(@PathVariable("conId") Long conId)
    {
        return AjaxResult.success(sysErrorConditionsService.selectSysErrorConditionsByConId(conId));
    }

    /**
     * 新增故障条件
     */
    @PreAuthorize("@ss.hasPermi('system:conditions:add')")
    @Log(title = "故障条件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysErrorConditions sysErrorConditions)
    {
        return toAjax(sysErrorConditionsService.insertSysErrorConditions(sysErrorConditions));
    }

    /**
     * 修改故障条件
     */
    @PreAuthorize("@ss.hasPermi('system:conditions:edit')")
    @Log(title = "故障条件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysErrorConditions sysErrorConditions)
    {
        return toAjax(sysErrorConditionsService.updateSysErrorConditions(sysErrorConditions));
    }

    /**
     * 删除故障条件
     */
    @PreAuthorize("@ss.hasPermi('system:conditions:remove')")
    @Log(title = "故障条件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{conIds}")
    public AjaxResult remove(@PathVariable Long[] conIds)
    {
        return toAjax(sysErrorConditionsService.deleteSysErrorConditionsByConIds(conIds));
    }
}
